<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('京东推荐商品明细')" />
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>
<!--<input type="hidden" id="data" value="${sellNo}" />-->
<div class="col-sm-12 select-table table-striped">
<!--    <input type="checkbox" name="test">-->
    <table id="bootstrap-table"></table>
</div>
<input type="hidden" th:value="${fileName}" id="fileName"/>
<input type="hidden" th:value="${classCode}" id="classCode"/>
<input type="hidden" th:value="${type}" id="type"/>

<div>


</div>
<th:block th:include="include :: footer" />

<script >
    var ctx = "[[@{/}]]";
</script>
<!--<script th:inline="javascript">-->
<script>
    var prefix = ctx + "jd/global";

    var fileName=$("#fileName").val();
    console.log("文件名" + "  " + fileName);


    $(function() {
        console.log('参数： ' + fileName)
        var options = {
            url : prefix +"/JDTJDetails/list/" +  fileName,
            createUrl: prefix + "/add",
            modalName: "京东推荐商品明细",
            columns: [
                {
                    field: 'id',
                    title: '商品编号',
                    width: 50,
                },
                {
                    field: 'goodsName',
                    title: '商品名称',
                    width: 200,
                },
                {
                    field: 'goodsPicUrl',
                    title: '商品图片',
                    detailView : true,
                    width: 120,
                    formatter: function (value) {
                        let url = 'http://' + value;
                        console.log(url);
                        return '<img loading="lazy" src="'+ url +'" alt="Smiley face" width="100" height="100">'
                    }
                },
                {
                    field: 'goodsPrice',
                    title: '单价',
                    align: "right",
                    width: 50,

                },
                {
                    field: 'commission',
                    title: '佣金',
                    align: "right",
                    width: 50,
                },

                {
                    title: '操作',
                    align: 'center',
                     width: 100,
                    formatter: function(value, row, index) {
                        var actions = [];
                        /* actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodscode + '\')"><i class="fa fa-plus"></i>新增</a> ');row.sellNo + row.startTime + row.endTime*/
                        actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="jdReferralLink(\'' + row.referralLink +"','"+ row.createTime+ "','"+ row.goodsNum+ '\')"><i class="fa fa-edit"></i>京东</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="submitSave(\'' + row.id +'\')"><i class="fa fa-edit"></i>选取</a> ');
                        /* actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');*/
                        // actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');
                        //actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                },


                ]
        };
        $.table.init(options);

    });

</script>
<script>
    function  jdReferralLink(p1,p2,p3){
        if(p1 != null) {
            console.log('京东推广链接：' + p1);
            //alert(p1);
            window.open(p1)
        }
    }

    /* 选取 保存记录 */
    function submitSave(id) {

        var classCode = $('#classCode').val();
        var type = $('#type').val();



        // 根据单品
        if(type == "3"){
            window.parent.ids.push(id);
            window.parent.$('#bootstrap-table').bootstrapTable('refresh');
            $.modal.close();
            return;
        }

        if(type == "2"){
            $.ajax({
                type: 'post',
                url: ctx + 'jd/class' + '/add',
                timeout: 30000,
                //	data : queryParams,
                data: {"id":id,"classCode":classCode,"type":type},
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    if(data.code == 0) {

                        //alert("数据插入成功")
                        // 刷新父页面表格
                        //var type = $('#type')


                        window.parent.$('#bootstrap-table').bootstrapTable('refresh');
                        $.operate.successCallback(data);

                    }else{
                        alert("数据插入异常")
                    }

                },
                error: function () {
                    alert("调用数据接口失败,请联系管理员");
                }
            });
            return;
        }

        if(type == "1"){
            $.ajax({
                type: 'post',
                url: prefix + '/add',
                timeout: 30000,
                //	data : queryParams,
                data: {"id":id,"classCode":classCode,"type":type},
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    if(data.code == 0) {

                        //alert("数据插入成功")
                        // 刷新父页面表格
                        //var type = $('#type')


                        window.parent.$('#bootstrap-table').bootstrapTable('refresh');
                        window.parent.$('#bootstrap-table-class').bootstrapTable('refresh');
                        $.operate.successCallback(data);

                    }else{
                        alert("数据插入异常")
                    }

                },
                error: function () {
                    alert("调用数据接口失败,请联系管理员");
                }
            });
        }

    }

</script>

</body>
</html>
